package com.ran.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ran.common.MessageResult;
import com.ran.entity.DO.UserDO;
import com.ran.mapper.UserMapper;
import com.ran.server.UserService;
import com.ran.utils.SpringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
    @Resource
    private UserMapper userMapper;
    public MessageResult login(UserDO user){
        if(userMapper==null) userMapper= SpringUtil.getBean(UserMapper.class);
        LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserDO::getUserName,user.getUserName());
        UserDO one = userMapper.selectOne(queryWrapper);
        if(one.getPassword().equals(user.getPassword())){
            return MessageResult.success(200,"success");
        }else {
            return MessageResult.error(222,"fail");
        }
    }
    public MessageResult logon(UserDO user){
        if(userMapper==null) userMapper=SpringUtil.getBean(UserMapper.class);
        LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserDO::getUserName,user.getUserName());
        UserDO one = userMapper.selectOne(queryWrapper);
        if(one==null){
            userMapper.insert(user);
            return MessageResult.success(200,"success");
        }else {
            return MessageResult.error(222,"fail");
        }
    }
}
